<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qtquick-connection-editor-signals.qdoc -->
  <title>Connecting Objects to Signals | Qt Creator Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt Creator Manual</a></td><td >Connecting Objects to Signals</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="index.html">Qt Creator Manual 4.11.1</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="qmldesigner-connections.html" />
  <link rel="next" href="quick-dynamic-properties.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qmldesigner-connections.html">Adding Connections</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="quick-dynamic-properties.html">Specifying Dynamic Properties</a>
</p><p/>
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Connecting Objects to Signals</h1>
<span class="subtitle"></span>
<!-- $$$quick-signals.html-description -->
<div class="descr"> <a name="details"></a>
<p>To receive a notification when a particular signal is emitted for a particular object, the object definition should declare a signal handler named <i>on&lt;Signal&gt;</i> where <i>&lt;Signal&gt;</i> is the name of the signal, with the first letter capitalized. The signal handler should contain the JavaScript code to be executed when the signal handler is invoked.</p>
<p>QML types have predefined signals that are emitted when users interact with the application. For example, the <a href="http://doc.qt.io/qt-5/qml-qtquick-mousearea.html">MouseArea</a> type from the <a href="http://doc.qt.io/qt-5/qtquick-qmlmodule.html">QtQuick</a> module has a <code>clicked</code> signal that is emitted whenever the mouse is clicked within the area. Since the signal name is <code>clicked</code>, the signal handler for receiving this signal is named <code>onClicked</code>.</p>
<p>For more information about signals and signal handlers, see <a href="http://doc.qt.io/qt-5/qtqml-syntax-signals.html">Signal and Handler Event System</a>.</p>
<p>To access a signal outside of the object that emits it, you can use the <a href="http://doc.qt.io/qt-5/qml-qtqml-connections.html">Connections</a> type for connecting to signals of arbitrary objects. A connections object can receive any signal from its specified target. You can connect objects to signals that are available to them in the <b>Connections</b> view.</p>
<p class="centerAlign"><img src="images/qmldesigner-connections.png" alt="" /></p><p>To connect objects to signals:</p>
<ol class="1" type="1"><li>In the <b>Connections</b> view, select the <b>Connections</b> tab.</li>
<li>Select the <img src="images/plus.png" alt="" /> (<b>Add</b>) button to add a connection.</li>
<li>Double-click the value in the <b>Target</b> column to add the object to connect to a signal.</li>
<li>Double-click the value in the <b>Signal Handler</b> column to select the signal that the connection will listen to from a list of all signals available for the object.</li>
<li>Double-click the value in the <b>Actions</b> column to specify the action to perform when the signal is emitted. You use JavaScript to specify the actions.</li>
</ol>
</div>
<!-- @@@quick-signals.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qmldesigner-connections.html">Adding Connections</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="quick-dynamic-properties.html">Specifying Dynamic Properties</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
